package club.qwertyzzz;

import java.awt.*;

/**
 * 爆炸类
 */
public class Blast {

    public static final int WIDTH = ResourceMgr.blast[0].getWidth();
    public static final int HEIGHT = ResourceMgr.blast[0].getHeight();

    private int x;
    private int y;
    private boolean liviing = true;
    private TankFrame tankFrame;

    /**
     * 描述当前爆炸所处的阶段
     */
    private int step = 0;

    public Blast(int x, int y, TankFrame tankFrame) {
        this.x = x;
        this.y = y;
        this.tankFrame = tankFrame;

        // 爆炸创建的时候产生声音
        ResourceMgr.playBlastSound();
    }

    /**
     * 画出爆炸, 每一帧只画出一次的爆炸效果
     * @param g
     */
    public void paint(Graphics g) {
        if(!liviing)
            return;
        g.drawImage(ResourceMgr.blast[step++], x, y, null);
        if(step >= ResourceMgr.blast.length) {
            die();
        }
    }

    /**
     * 爆炸从界面当中移除
     */
    public void die() {
        liviing = false;
    }
}
